package com.yl.mytest;

import android.util.Log;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
 
public class SerialExecutorExample {

    private final ExecutorService serialExecutor;

    public SerialExecutorExample() {
        Log.e("========", "=======SerialExecutorExample======");
        // 创建一个只有一个线程的线程池，确保任务按照提交的顺序执行
        serialExecutor = Executors.newSingleThreadExecutor();
    }

    public void executeTask(final Runnable task) {
        Log.e("========", "=======executeTask======");
        serialExecutor.execute(task);
    }

    public void shutdown() {
        serialExecutor.shutdown(); // 当不再需要执行任何任务时，关闭ExecutorService
        Log.e("========", "=======shutdown======");
    }
}